<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户编辑</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated">
        <div class="row">
            <div class="col-sm-8">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户编辑</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t layui-form" id="commentForm" method="post" action="{:url('examine/edit')}">
                            <input type="hidden" value="{$info['id']}" name="id" />
                            <div class="form-group">
                                <label class="col-sm-3 control-label">顾客名称</label>
                                <div class="input-group col-sm-4">
                                    <input type="text" class="form-control" required="" aria-required="true" name="name" value="{$info['name']}">
                                </div>
                            </div>
                            <div class="form-group layui-form-item form-inline" style="height: 60px;">
                                <label class="col-sm-3 control-label">用户头像：</label>
                                <!-- <div class="input-group col-sm-2">
                                    <button type="button" class="layui-btn layui-btn-small" id="up-avatar">
                                        <i class="layui-icon"></i>上传图片</button>
                                </div> -->
                                <div class="input-group col-sm-3" id="avatar">
                                    <img src="{$info['headimgurl']}" width="40px" height="40px" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">微信openid：</label>
                                <div class="input-group col-sm-4">
                                    <input id="openid" type="text" class="form-control" placeholder="" readonly value="{$info['openid']}">
                                </div>
                            </div>
                            <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">性别：</label>
                                <div class="input-group col-sm-4">
                                    {foreach name="Think.config.sex" item="vo" key="key"}
                                    <input type="radio" name="sex" value="{$key}" title="{$vo}" {if ($info[ 'sex']==$key)} checked {/if}> {/foreach}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">手机号：</label>
                                <div class="input-group col-sm-4">
                                    <input id="openid" type="text" class="form-control" placeholder="" readonly value="{$info['mobile']}">
                                </div>
                            </div>
                            <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">审核通过：</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="status" lay-skin="switch" <?=$info[ 'status']==1 ? 'checked' : '' ?> ">
                                </div>
                            </div>
                            <div class="form-group layui-form-item ">
                                <label class="col-sm-3 control-label ">选择客服：</label>

                                <div class="input-group col-sm-4 layui-form ">
                                    <select lay-verify="required" name="service_id" lay-filter="service" lay-verify="required" lay-search="">
                                        <option value=" ">选择客服：</option>
                                        {foreach name="service" item="vo"}
                                        <option value="{$vo->id}" {if $info['service_id'] == $vo->id} selected {/if} >{$vo->user_name}</option>
                                    {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">设置事业中心负责人</label>
                                <div class="layui-input-inline">
                                    <select name="department_id" id="department_id" lay-filter="department" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                        {foreach name="department" item="vo"}
                                        <option value="{$vo->id}" {if $info['department_id'] == $vo->id} selected {/if}>{$vo->user_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">设置销售老师</label>
                                <div class="layui-input-inline">
                                    <select name="market_id" id="market_id" lay-filter="market" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                        {foreach name="market" item="vo"}
                                        <option value="{$vo->id}" {if $info['market_id'] == $vo->id} selected {/if}>{$vo->user_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">设置门店负责人</label>
                                <div class="layui-input-inline">
                                    <select name="shop_id" id="shop_id" lay-filter="shop" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                        {foreach name="shop" item="vo"}
                                        <option value="{$vo->id}" {if $info['shop_id'] == $vo->id} selected {/if}>{$vo->user_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <!-- <div class="form-group layui-form-item">
                                <label class="col-sm-3 control-label">用户文件</label>
                                <input type="hidden" id="user_file" name="user_file" value="{$info['user_file1']}" />
                                <button type="button" class="layui-btn layui-btn-sm" id="file_btn"><i class="layui-icon"></i>上传文件</button>
                                <a id="file_download" href="{$info['user_file1'] ?: 'javascript:void(0)'}" class="layui-btn layui-btn-normal layui-btn-sm {$info['user_file1'] ? '' : 'layui-btn-disabled'}">点击下载</a>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm {$info['user_file1'] ? '' : 'layui-btn-disabled'}" id="file_name"><i class="layui-icon"></i> 删除</button>
                            </div> -->
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-6">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <script src="__JS__/jquery.min.js?v=2.1.4"></script>
    <script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
    <script src="__JS__/content.min.js?v=1.0.0"></script>
    <script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
    <script src="__JS__/plugins/validate/messages_zh.min.js"></script>
    <script src="__JS__/plugins/layer/layer.min.js"></script>
    <script src="__JS__/layui/layui.js"></script>
    <script src="__JS__/jquery.form.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'upload'], function() {
            var form = layui.form;
            var upload = layui.upload;
            //执行实例

            form.on('select(service)', function(value) {
                $("#service_id").val(value.value);
                $('#shop_id').children('option').first().nextAll().remove()
                $('#market_id').children('option').first().nextAll().remove()
                add($('#department_id'), value.value);
                form.render("select");
            });
            form.on('select(department)', function(value) {
                $("#department_id").val(value.value);
                add($('#market_id'), value.value);
                $('#shop_id').children('option').first().nextAll().remove()
                form.render("select");
            });
            form.on('select(market)', function(value) {
                $("#market_id").val(value.value);
                add($('#shop_id'), value.value);
                form.render("select");
            });

            //指定允许上传的文件类型
            upload.render({
                elem: '#file_btn',
                exts: 'zip|rar|xlsx|xls|doc|docx',
                url: '/admin/upload/uploadFile',
                accept: 'file',
                done: function(res) {
                    layer.msg('上传成功');
                    $('#user_file').val(res.data.src);
                    $('#file_name').removeClass('layui-btn-disabled');
                    $('#file_download').removeClass('layui-btn-disabled').attr('href', res.data.src);
                },
            });
            $('#file_name').click(() => {
                $('#file_name').addClass('layui-btn-disabled');
                $('#user_file').val('');
                $('#file_download').addClass('layui-btn-disabled').attr('href', 'javascript:void(0)').html('未上传文件');
                layer.msg('已清除');
            });

            function add(obj, id) {
                $.getJSON(
                    "{:url('admin/users/children')}", {
                        "id": id
                    },
                    (data) => {
                        obj.children('option').first().nextAll().remove();
                        $.each(data, (i, v) => {
                            obj.append(new Option(v, i))
                        })
                        form.render("select");
                    }
                )
            }
        });

        var index = '';

        function showStart() {
            index = layer.load(0, {
                shade: false
            });
            return true;
        }

        function showSuccess(res) {

            layer.ready(function() {
                layer.close(index);
                if (1 == res.code) {
                    layer.alert(res.msg, {
                        title: '友情提示',
                        icon: 1,
                        closeBtn: 0
                    }, function() {
                        window.location.href = res.data;
                    });
                } else if (111 == res.code) {
                    window.location.reload();
                } else {
                    layer.msg(res.msg, {
                        anim: 6
                    });
                }
            });
        }

        $(document).ready(function() {
            // 添加管理员
            var options = {
                beforeSubmit: showStart,
                success: showSuccess
            };

            $('#commentForm').submit(function() {
                $(this).ajaxSubmit(options);
                return false;
            });
        });

        // 表单验证
        $.validator.setDefaults({
            highlight: function(e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            },
            success: function(e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            },
            errorElement: "span",
            errorPlacement: function(e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none"
        });
    </script>
</body>

</html>